//
//  TitleButton.m
//  微博2期
//
//  Created by J on 15/11/28.
//
//

#import "TitleButton.h"

@implementation TitleButton

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setTitleColor: [UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];

    }
    
    return self;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    //如果仅仅是调整按钮内部titleLabel和imageView位置 那么我们在layoutSubviews中单独设置位置即可
    //计算titleLabel的frame
    self.titleLabel.x = self.imageView.x;
    
    //计算imageView的frame
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);//MaxX ＝ x+width

}
- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    
    [super setTitle:title forState:state];
    [self sizeToFit];

}


- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    
    [super setImage:image forState:state];
    [self sizeToFit];

    
}

@end
